package com.mmm.nlp.impl;

import com.mmm.nlp.TextWriter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: Zhendong
 * Date: 4/21/13
 * Time: 12:36 AM
 * To change this template use File | Settings | File Templates.
 */
public class BufferedTextWriter implements TextWriter
{
  private static final int BUFFERED_LINE_NUMBER = 1000;
  private BufferedWriter writer = null;
  private int count = 0;

  public BufferedTextWriter(String outputFilePath)  throws IOException
  {
    writer = new BufferedWriter(new FileWriter(outputFilePath));
  }

  @Override
  public void write(String text) throws IOException
  {
    writer.write(text);
    if(count==BUFFERED_LINE_NUMBER)
    {
      writer.flush();
      count = 0;
    }
  }

  public void flush() throws IOException
  {
    writer.flush();
  }
}
